package xyf.p04.tree;

import commons.TreeNode;

/**
 * ClassName: P0538_ConvertBST
 * Description:
 * Author: xyf
 * Date: 9/8/22 6:19 PM
 * Version: 1.0
 **/
public class P0538_ConvertBST
{
    int sum = 0;

    public TreeNode convertBST(TreeNode root)
    {
        dfs(root);
        return root;
    }

    private void dfs(TreeNode root)
    {
        if (root == null)
        {
            return;
        }

        dfs(root.right);

        sum += root.val;

        root.val = sum;

        dfs(root.left);
    }
}
